<?php

namespace App\Models\Workflow;

use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;

class WorkflowV2OrderNodeHandlerModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'workflow_v2_order_node_handlers';

    protected $fillable = [
        'workflowOrderNodeId',
        'workflowTemplateNodeId',
        'handlerType',
        'handlerUid',
        'handlerStatus',
        'isDeleted',
    ];

    const HANDLER_STATUS_WAIT   = 0; // 未处理
    const HANDLER_STATUS_FINISH = 1; // 已处理

    /**
     * 用户完成节点
     * @param int $workflowTemplateNodeId
     * @param int $handlerUid
     * @return int
     */
    public static function finish(int $workflowOrderNodeId, int $handlerUid): int
    {
        return self::query()
                   ->where('workflowOrderNodeId', $workflowOrderNodeId)
                   ->where('handlerUid', $handlerUid)
                   ->update(['handlerStatus' => self::HANDLER_STATUS_FINISH]);
    }
}
